<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [["name", "twj"], ["age", 100]]
        console.log(Object.fromEntries(arr)) //{name: 'twj', age: 100}
        //用处1：map转对象
        let m = new Map()
        m.set("name", "twj")
        m.set("age", 100)
        console.log(Object.fromEntries(m)) //{name: 'twj', age: 100}
        //用处2：请求参数转对象
        let str = "name=twj&age=18"
        let searchParams = new URLSearchParams(str)
        console.log(Object.fromEntries(searchParams)) //{name: 'twj', age: '18'}
        //用处3：将一个对象转换成另一个对象的形式
        let obj = {
            "A": ["A1", "A2", "A3"],
            "B": ["B1", "B2"],
            "C": ["C1"]
        }
        let myarr = Object.entries(obj) //转成数组
        let mynewarr = myarr.map(([key, value]) =>
            [key, value.length]
        )
        console.log(Object.fromEntries(mynewarr)) //{A: 3, B: 2, C: 1}
    </script>
</body>

</html>